<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ page import="weaver.common.DateUtil" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.interfaces.cese.duss.ceseutil.WorkflowCreateHandler" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="rs1" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="bb" class="weaver.general.BaseBean"/>
<%
    String ids = Util.null2String( request.getParameter( "ids" ) );//项目名称
    bb.writeLog( "ids=" + ids );
    User user = HrmUserVarify.getUser( request, response );
    String userid = user.getUID()+"";
    String workflowId = "34030";
    String requestName = "";
    String IsNextFlow = "0";
    Map requestMainMap = new HashMap<>();
    WorkflowCreateHandler createHandler = new WorkflowCreateHandler();

    String sql1 = "select distinct xmmc from formtable_main_698 where id in (" + ids + ")";
    bb.writeLog( sql1 );
    rs.executeQuery( sql1 );
    rs.next();
    String xmmc = Util.null2String( rs.getString("xmmc") );//项目名称

    String sql2 = "select a.id,a.xmbh,nvl(b.bzjjey,0) bzjjey from formtable_main_694 a left join formtable_main_694_Dt4 b on a.id = b.mainid where  a.id ="+xmmc;
    rs.executeQuery( sql2 );
    rs.next();
    String bzjjey = Util.null2String( rs.getString( "bzjjey" ) );//保证金金额 
    requestName = "投标邀请-" + DateUtil.getCurrentDate();
    requestMainMap.put( "sqr", userid);//申请人
    requestMainMap.put( "zblx", xmmc );//项目名称
    requestMainMap.put( "zblx1", xmmc );//项目编号
    requestMainMap.put( "bzjje", bzjjey );//项目编号

    String requestid = createHandler.WorkflowCreateByRequestMap( userid , workflowId, requestName, IsNextFlow, requestMainMap );
    String sql3 = "select id from formtable_main_680 where requestid="+requestid;
    rs.executeQuery(sql3);
    rs.next();
    String mainid = Util.null2String( rs.getString( "id" ));
    String sql4 = "select  gysmc,gysmcrl  from formtable_main_698 where id in (" + ids + ") and sftg=0";
    rs.executeQuery(sql4);
    while (rs.next()) {
        String gysmc = Util.null2String( rs.getString( "gysmc" ) );//项目编号
        String gysmcrl = Util.null2String( rs.getString( "gysmcrl" ) );//项目编号
        String sql5="insert into formtable_main_680_dt1 (mainid,gysmc,gysrl) values(?,?,?)";
        rs.executeUpdate(sql5,new Object[]{mainid,gysmc,gysmcrl});
    }

    if(Util.getIntValue(requestid)>0){
%>
<script language="javascript" type="text/javascript">
    //alert("邀请成功");
    window.location.href="/spa/workflow/static4form/index.html#/main/workflow/req?requestid="+<%=requestid%>;
    //window.close();
</script>
<%}else {%>
<script language="javascript" type="text/javascript">
    alert("邀请失败");
    //window.location.href="/wui/index.html#/main?menuIds=-12,-633";
    window.close();
</script>
<%}%>



